<?php
include $_SERVER['DOCUMENT_ROOT'].'/view/include/index.php';
/// Delete Season
if (isset($_GET['delete'])) {
    $seasonDAO->delete($_GET['delete']);
    header("location:/view/season/");
}
/// Update Season
if (isset($_GET['update'])) {
    $smarty->assign("season", $seasonDAO->loadById($_GET['update']));
    $smarty->display("season/update.tpl");
}
/// New Season
if (isset($_GET['new'])) {
    $smarty->display("season/new.tpl");
}

if (isset($_POST['proc'])) {
    if ($_POST['proc'] == "upsert") {
        empty($_POST['id']) ? $id = null : $id = $_POST['id'];
        $season = array(
            'id' => $id,
            'name' => $_POST['name'],
            'league' => array('id' => $_POST['league']),
            'seasonType' => $_POST['type'],
            'shortName' => $_POST['shortName'],
            'abbreviation' => $_POST['abbreviation'],
            'status' => $_POST['status'],
        );
        $seasonDAO->upsert($season);
    }
    header("location:/view/season/");
}

$smarty->assign("seasons", $seasonDAO->loadAll());
$smarty->display("season/index.tpl");
?>
